package main

import (
	"fmt"
	"regexp"
)

const text = `my email is phpfan@yeah.net
email1 is coder.fan@qq.com
email2 is phperfan@126.com
email3 is test@abc.com.cn
`

func main() {
	//regexp.Compile()
	//re := regexp.MustCompile(`[\w.]+@\w+\.\w+`)
	re := regexp.MustCompile(`([\w.]+)@(\w+)([.\w]+)`)

	// 匹配单个
	//match := re.FindString(text)

	// 匹配索格
	//match := re.FindAllString(text,-1)

	// 提取字符串
	match := re.FindAllStringSubmatch(text, -1)
	fmt.Println(match)

	for _, value := range match {
		fmt.Println(value)
	}
}
